package activity

import (
	"activity_srv/activityclient"
	"api/internal/svc"
	"api/internal/types"
	"context"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateSeckillOrderLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCreateSeckillOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateSeckillOrderLogic {
	return &CreateSeckillOrderLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CreateSeckillOrderLogic) CreateSeckillOrder(req *types.CreateSeckillOrderRequest) (resp *types.Response, err error) {
	order, err := l.svcCtx.ActivityRpc.CreateSeckillOrder(l.ctx, &activityclient.CreateSeckillOrderRequest{
		UserId:        req.UserId,
		SeckillGoodId: req.GoodSkuId,
	})
	if err != nil {
		return &types.Response{
			Code:    400,
			Message: err.Error(),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "success",
		Data:    order,
	}, nil
}
